#!/usr/bin/python

from FlatSpeedCurve import *
from LinearDemandCurve import *
from StirlingModel import *
from pylab import *

ts = [ 25.0/60.0, 30.0/60.0, 30.0/60.0, 35.0/60.0 ]
ds = [ 200.0, 200.0, 200.0, 200.0 ]
t = arange( 0.0, 2.0+0.01, 0.01 )
#t = [ 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0 ]

speed = FlatSpeedCurve( ts, ds, t )
v = speed.getSpeed()

demand = LinearDemandCurve( 10.0, 50.0, 300.0 )
D = demand.getDemand( v )

A = 1.5e-4;
B = 2.0
C = 1.0
E = 1.0
VdotO2min = 10.0
VdotO2max = 50.0

model = StirlingModel( A, B, C, E, VdotO2min, VdotO2max )
model.solve( t, D, 10.0*8.0/6.0 )
VdotO2aerobic = model.getAerobic()
VdotO2anaerobic = model.getAnaerobic()
VO2anaerobic = model.getAnaerobicTotal()
VO2aerobic = model.getAerobicTotal()
percent = VO2anaerobic / ( VO2aerobic + VO2anaerobic )

print( "VO2aerobic = %g mL/kg" % ( VO2aerobic ) )
print( "VO2anaerobic = %g mL/kg" % ( VO2anaerobic ) )
print( "%g percent anaerobic" % ( percent*100.0 ) )

#print( "t\tv\tD\tVdotA\tVdotAn" )
#for i in range( 0, len(t) ):
#	print( "%g\t%g\t%g\t%g\t%g" % ( t[i], v[i], D[i], VdotO2aerobic[i], VdotO2anaerobic[i] ) )

plot( t, D, t, VdotO2aerobic, t, VdotO2anaerobic )
show()
